import java.util.Arrays;

public class j4 {
    /*10打印二维数组进阶*/
    public static void main(String[] args) {
        int[][]wer={{12,3,5},{4,5,6}};
        for (int i=0;i<wer.length;i++){//获取的是二维数组行数
            for (int j=0;j<wer[i].length;j++){//获取的是二维数组第i行的列数
                System.out.print(wer[i][j]+" ");
            }
            System.out.println();
        }
    }
    /*10利用字符串深度打印二维数组*/
    public static void main16(String[] args) {
        int[][]wer={{12,3,5},{4,5,6}};
        String poo=Arrays.deepToString(wer);
        System.out.println(poo);
    }
    /*for 循环打印二维数组*/
    public static void main15(String[] args) {

    int[][]wer={{12,3,5},{4,5,6}};
    for(int i=0;i<2;i++){
        for(int j=0;j<3;j++){
            System.out.print(wer[i][j]+"    ");// 打印元素后加空格
           }
        System.out.println(); // 每行结束后换行
       }
    }

    /*9二维数组的定义*/
    public static void main14(String[] args) {
        int [] []wer={{12,3,5},{4,5,6,7,8,9}};
        int[][]wty=new int [][]{{12,3,5},{4,5,6,7,8,9}};
        int[][]weq=new int [2][3];
    }
    /*8利用拷贝公式拷贝数组*/
    public static void main13(String[] args) {
        int []ret=new int[]{1,2,3,4,4,5,6,7,7};
        int []wmb=Arrays.copyOfRange(ret,1,6);/*拷贝数组下标区间*/
        int[]fvp=Arrays.copyOf(ret,ret.length);/*拷贝数组*/
        System.out.println(Arrays.toString(wmb));
        System.out.println(Arrays.toString(fvp));
    }
    /*8利用遍厉拷贝数组*/
    public static int [] qwe(int []wrs){
        int []copy=new int[wrs.length];
        for (int i=0;i<wrs.length;i++){
            copy [i]=wrs[i];
        }
        return copy;
    }
    public static void main12(String[] args) {
        int  []ret=new int[]{1,2,23,4,5,6,7,8};
        int []copy=qwe(ret);
        System.out.println(Arrays.toString(copy));
    }
    /*7冒泡排序方法*/
 public static void bluee(int []qwe){
        for (int i=0;i<qwe.length-1;i++){//外层循环控制趟数
            for(int j=0;j<qwe.length-1-i;j++){
                if (qwe[j]>qwe[j+1]){
                    int tam=qwe[j];
                    qwe[i]=qwe[j+1];
                    qwe[j+1]=tam;
                }
            }
        }
    }
    public static void main10(String[] args) {
        int []qwe=new int[]{1,2,3,1,4,5};
        bluee(qwe);//调用bluee方法名将qwe参数传递；
        System.out.println(Arrays.toString(qwe));
    }
    /*7冒泡排序，下标查找*/
    public static void main11(String[] args) {
        int []i=new int[]{1,2,3,12,45,34,6,7,8,9};
        System.out.println("排序前"+Arrays.toString(i));
        Arrays.sort(i); //冒泡排序指令
        System.out.println("排序后"+Arrays.toString(i));
         int dox=Arrays.binarySearch(i,3);//下标查找
        System.out.println(dox);
    }
    /*6二分查找*/
    public static int foc1(int[]arr2,int x) {
        int left = 0;
        int right = arr2.length - 1;
        while (left <= right) {
            int mid = (left + right) / 2;
                if (arr2[mid] == x) {
                     return mid;
                    }else if(arr2[mid]<x) {
                        left=mid+1;
                         } else{
                 right=mid-1;
                }
        }
        return -1;
    }
    public static void main9(String[] args) {
        int[]arr6=new int[]{1,2,3,4,5,6,7,8,};
        int dox=foc1(arr6,5);
        System.out.println(dox);
    }

  /*5  利用遍历查找指定下标*/
    public static int foc(int[]arr,int x){
        for (int i=0;i<arr.length;i++){
            if (arr[i]==x){
                return i;
            }
        }
        return -1;
    }
    public static void main8(String[] args) {
        int []arr=new int[]{1,2,3,4,5,67,8,9};
                int dox=foc(arr,8);
        System.out.println(dox);
    }
    /*  传递引用，一个引用只能只指向一个对象*/
    public static void foc1(int []arr){
        arr=new int[]{9,8,7,6,5,4};//改变的指向不影响输出
    }
    public static void main7(String[] args) {
        int []arr=new int[]{1,2,3,4,5};
        foc1(arr);
        System.out.println(Arrays.toString(arr));
    }
  /*  传递引用，一个引用只能指向一个对象*/
    public static void foc(int []arr){
        arr[0]=99;//改变的值影响输出
    }
    public static void main6(String[] args) {
        int []arr=new int[]{1,2,3,4,5};
        foc(arr);
        System.out.println(Arrays.toString(arr));
    }
    /*  3将数组扩大两倍*/
    public static int[] gip(int[]arr){
        for (int i=0;i< arr.length;i++){
            arr[i]=arr[i]*2;
        }
        return arr;
    }
    public static void main5(String[] args) {
        int []arr=new int []{1,2,3,4};
        System.out.println(Arrays.toString(arr));
        gip(arr);
        System.out.println(Arrays.toString(arr));
    }
  /*  3将数组扩大两倍*/
 public static int[] AWM (int[] ARR){
 int []ret=new int[ARR.length];
 for(int i=0;i<ARR.length;i++){
     ret[i]=ARR[i]*2;
    }
        return ret;
 }
  public static void main4(String[] args) {
      int []arr={1,2,3,4,5,6,7};
      int[] tam=AWM(arr);
      System.out.println(Arrays.toString(tam));
      System.out.println(Arrays.toString(arr));
  }
    /*2利用字符串打印数组*/
    public static void main3(String[] args) {
        int []arr=new int[]{1,2,3,4,5,6,7};
        String RET= Arrays.toString(arr);
        System.out.println(RET);
    }
    /*1for each循环打印数组*/
    public static void main2(String[] args) {
        int []arr={1,2,3,4,5,6};
        for (int x:arr){
            System.out.println(x);
        }
    }
    /*1for 循环打印数组*/
    public static void main1(String[] args) {
        int[]arr= new int[]{1,2,3,4,5,6};
                                            //第一种数组定义
        /*int[]arr={1,2,3,4,5,6};*/

                                            //第二中数组定义
        /*int[]arr4={1,2,3,4,5,6};/int[]arr4;
        arr4= new int[4]; */                //第三种数组定义
        for (int i=0;i< arr.length;i++){
            System.out.println(""+arr[i]);
        }
    }
}
